package com.atom.module.document.utils;

import androidx.recyclerview.widget.DiffUtil;

import java.util.List;

/**
 * All rights Reserved, Designed By www.rongdasoft.com
 *
 * @version V1.0
 * @Title: DiffUIDataUtil
 * @Description:
 * @author: wuyongzheng
 * @date: 2022/3/31
 * @Copyright: 2022/3/31 www.rongdasoft.com Inc. All rights reserved.
 */
public class DiffUIDataUtil<T extends DiffUIDataUtil.Differ<T>> extends DiffUtil.Callback {

    interface Differ<T> {
        // 传递一个旧的数据给你，问你是否和你标示的是同一个数据
        boolean isSame(T old);

        // 你和旧的数据对比，内容是否相同
        boolean isUiContentSame(T old);
    }

    private List<T> mOldList;
    private List<T> mNewList;

    public DiffUIDataUtil(List<T> mOldList, List<T> mNewList) {
        this.mOldList = mOldList;
        this.mNewList = mNewList;
    }

    @Override
    public int getOldListSize() {
        return mOldList.size();
    }

    @Override
    public int getNewListSize() {
        return mNewList.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        return mNewList.get(newItemPosition).isSame(mOldList.get(oldItemPosition));
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        return mNewList.get(newItemPosition).isUiContentSame(mOldList.get(oldItemPosition));
    }
}
